#include "bytetableview.h"

#include <QHeaderView>


#define DEFAULT_CELL_HEIGHT				18


ByteTableView::ByteTableView(QWidget *parent)
	: QTableView(parent)
{
	verticalHeader()->setDefaultSectionSize(DEFAULT_CELL_HEIGHT);
}

ByteTableView::~ByteTableView()
{

}

QStyleOptionViewItem ByteTableView::viewOptions() const
{
	return QTableView::viewOptions();
	QStyleOptionViewItem vo = QTableView::viewOptions();
	vo.displayAlignment = Qt::AlignCenter;
	return vo;
}

void ByteTableView::on_ViewModeChanged( ViewMode vm )
{
	int w = 0;
	int h = 0;
	bool showGrid = true;
	bool vscrlbar = true, hscrlbar = true;
	switch (vm)
	{
	case vmDecimal: w = 28; h = DEFAULT_CELL_HEIGHT; break;
	case vmHEX: w = 24; h = DEFAULT_CELL_HEIGHT; break;
	case vmBinary: w = 56; h = DEFAULT_CELL_HEIGHT; break;
	case vmBinaryInverted: w = 56; h = DEFAULT_CELL_HEIGHT; break;
	case vmSymbol: w = 18; h = DEFAULT_CELL_HEIGHT; break;
	case vmBitPixel: w = 8; h = 1; showGrid = false; hscrlbar = vscrlbar =  false;  break;
	}
	horizontalHeader()->setDefaultSectionSize(w);
	verticalHeader()->setDefaultSectionSize(h);
	horizontalHeader()->setVisible(hscrlbar);
	verticalHeader()->setVisible(vscrlbar);
	setShowGrid(showGrid);
}
